/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Form;

import BLL.BLLManu;
import BLL.BLLProduct;
import DTO.DTOManufacture;
import DTO.DTOProduct;
import java.awt.Image;
import java.awt.event.KeyEvent;
import java.io.File;
import java.text.NumberFormat;
import java.util.Date;
import javax.imageio.ImageIO;
import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter;

/**
 *
 * @author Pham
 */
public class JDialogProduct extends javax.swing.JDialog {
    BLLManu bllManu;
    BLLProduct bllPro;
    JFileChooser fileChooserImage;
    File fileImage;
    NumberFormat numberformat;
    int update = -1;
    /**
     * Creates new form JDialogProduct
     */
    public JDialogProduct(java.awt.Frame parent, boolean modal, int idUpdate) {
        super(parent, modal);
        bllManu = new BLLManu();
        bllPro = new BLLProduct();
        initComponents();
        this.update = idUpdate;
        loadDatatoCombobox();
        if(idUpdate != -1){
            loadData(idUpdate);
            lbTitle.setText("Sửa sản phẩm");
            btnNew.setVisible(false);
        }
            
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    private void initComponents() {//GEN-BEGIN:initComponents

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        cbManu = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        txtProPrice = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        lbID = new javax.swing.JLabel();
        btnChooseImg = new javax.swing.JButton();
        lbImage = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        txtProWarranty = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtProPromotion = new javax.swing.JTextArea();
        jLabel10 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        txtProDescription = new javax.swing.JTextArea();
        txtProName = new javax.swing.JTextField();
        lbTitle = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        btnSave = new javax.swing.JButton();
        btnNew = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, new java.awt.Color(0, 0, 102)));

        jLabel1.setText("Tên SP");

        jLabel2.setText("Hãng");

        cbManu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbManuActionPerformed(evt);
            }
        });

        jLabel3.setText("Giá bán");

        txtProPrice.setPreferredSize(new java.awt.Dimension(100, 25));
        txtProPrice.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtProPriceKeyTyped(evt);
            }
        });

        jLabel4.setText("Hình");

        jLabel5.setText("Mã SP");

        btnChooseImg.setText("Chọn hình");
        btnChooseImg.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnChooseImgActionPerformed(evt);
            }
        });

        lbImage.setMaximumSize(new java.awt.Dimension(71, 71));
        lbImage.setPreferredSize(new java.awt.Dimension(70, 70));

        jLabel8.setText("Thời gian bảo hành");

        jLabel9.setText("Khuyến mãi");

        jScrollPane1.setPreferredSize(new java.awt.Dimension(183, 86));

        txtProPromotion.setColumns(20);
        txtProPromotion.setRows(5);
        txtProPromotion.setPreferredSize(new java.awt.Dimension(164, 100));
        jScrollPane1.setViewportView(txtProPromotion);

        jLabel10.setText("Mô tả SP");

        txtProDescription.setColumns(20);
        txtProDescription.setRows(5);
        jScrollPane2.setViewportView(txtProDescription);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5)
                    .addComponent(jLabel2)
                    .addComponent(jLabel1)
                    .addComponent(jLabel4)
                    .addComponent(jLabel3))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(lbID, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(cbManu, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(txtProName, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 193, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(txtProPrice, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(btnChooseImg)
                    .addComponent(lbImage, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(59, 59, 59)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel10)
                    .addComponent(jLabel9)
                    .addComponent(jLabel8))
                .addGap(4, 4, 4)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(txtProWarranty, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 383, Short.MAX_VALUE)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(11, 11, 11)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtProWarranty, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel9)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 172, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(123, 123, 123)
                                .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(cbManu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(txtProPrice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(15, 15, 15)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel4)
                                    .addComponent(btnChooseImg, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(29, 29, 29)
                                .addComponent(txtProName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(lbID, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGap(27, 27, 27)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(lbImage, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        lbTitle.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        lbTitle.setForeground(new java.awt.Color(153, 0, 51));
        lbTitle.setText("Thêm sản phẩm");

        jButton1.setBackground(new java.awt.Color(204, 204, 204));
        jButton1.setText("Đóng");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        btnSave.setBackground(new java.awt.Color(0, 102, 0));
        btnSave.setForeground(new java.awt.Color(255, 255, 255));
        btnSave.setText("Lưu");
        btnSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSaveActionPerformed(evt);
            }
        });

        btnNew.setBackground(new java.awt.Color(153, 153, 255));
        btnNew.setForeground(new java.awt.Color(0, 0, 153));
        btnNew.setText("Nhập lại");
        btnNew.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNewActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(btnNew, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnSave, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addGap(326, 326, 326)
                .addComponent(lbTitle)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(lbTitle)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(btnNew, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnSave, javax.swing.GroupLayout.DEFAULT_SIZE, 39, Short.MAX_VALUE)
                    .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        pack();
    }//GEN-END:initComponents

    private void cbManuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbManuActionPerformed
        //        DTOManufacture dtoManu = (DTOManufacture)cbManu.getSelectedItem();
        //        System.out.print(dtoManu.getManuID());
    }//GEN-LAST:event_cbManuActionPerformed

    private void txtProPriceKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtProPriceKeyTyped
        char c = evt.getKeyChar();
        if(!Character.isDigit(c) || c == KeyEvent.VK_BACK_SPACE || c == KeyEvent.VK_DELETE)
        evt.consume();
    }//GEN-LAST:event_txtProPriceKeyTyped

    private void btnChooseImgActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnChooseImgActionPerformed
        try
        {
            fileChooserImage = new JFileChooser();
            String[] suff = ImageIO.getReaderFileSuffixes();
            for(int i = 0; i< suff.length; i++){
                FileFilter filter = new FileNameExtensionFilter(suff[i] + "file", suff[i]);
                fileChooserImage.addChoosableFileFilter(filter);
            }
            fileChooserImage.showOpenDialog(this);
            fileImage = fileChooserImage.getSelectedFile();
            if(fileImage != null)
            {
                ImageIcon icon = new ImageIcon(fileImage.toString());
                ImageIcon setIcon = resizeImg(icon, 128, 115);
                lbImage.setIcon(setIcon);
            }

        }
        catch(Exception ex)
        {
            JOptionPane.showMessageDialog(this, "Error: " + ex.getMessage());
        }
    }//GEN-LAST:event_btnChooseImgActionPerformed

    private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveActionPerformed
//        DTOProduct dtoPro = new DTOProduct();
        DTOManufacture dtoManu = (DTOManufacture)cbManu.getSelectedItem();
        try{
            if("".equals(checkInput())){
                String ProName = txtProName.getText();
                long ProPrice = Long.valueOf(txtProPrice.getText());
                String ProImage = "";
                String ProWarranty = txtProWarranty.getText();
                String ProPromotion = txtProPromotion.getText();
                String ProDescription = txtProDescription.getText();
                if(fileImage != null)
                    ProImage = fileImage.getName();
                Date ProDate = new Date();
                
//                dtoPro.setProductName(ProName);
//                dtoPro.setManu(dtoManu);
//                dtoPro.setProductPrice(ProPrice);
//                dtoPro.setProductImage(ProImage);
//                dtoPro.setProductWarranty(ProWarranty);
//                dtoPro.setProductQuantity(0);
//                dtoPro.setProductPromotion(ProPromotion);
//                dtoPro.setProductDescription(ProDescription);
//                dtoPro.setProductDateUpdate(ProDate);
                DTOProduct dtopro = new DTOProduct(ProName, 0, ProImage, ProDate, ProDescription, ProWarranty, ProPromotion, ProPrice, dtoManu);
                if(update == -1)
                {
                    if(bllPro.insertRowProduct(dtopro))
                    {
                        if(ProImage != ""){
                            if(!bllPro.writeImage(fileImage, "D:\\wamp\\www\\shopcomputer\\public\\default\\images\\products\\" + ProImage))
                            JOptionPane.showMessageDialog(null, "Không thể lưu hình");
                        }
                        JOptionPane.showMessageDialog(null, "Đã thêm sản phẩm");
                    }
                }
                else
                {
                    DTOProduct currentPro = bllPro.getProductbyID(Integer.valueOf(lbID.getText()));
                    dtopro.setProductID(Integer.valueOf(lbID.getText()));
                    if(bllPro.updateRowProduct(dtopro))
                    {
                        if(currentPro.getProductImage() != ""){
                            if(!bllPro.deleteImage("D:\\wamp\\www\\shopcomputer\\public\\default\\images\\products\\" + currentPro.getProductImage()))
                                JOptionPane.showMessageDialog(null, "Không thể xóa hình");
                        }
                        if(ProImage != "")  {
                            if(!bllPro.writeImage(fileImage, "D:\\wamp\\www\\shopcomputer\\public\\default\\images\\products\\" + ProImage))
                                JOptionPane.showMessageDialog(null, "Không thể lưu hình");  
                        }
                        JOptionPane.showMessageDialog(null, "Đã cập nhật sản phẩm");
                    }
                }
                
                
            }
            else
                JOptionPane.showMessageDialog(null, checkInput());
        }
        catch(Exception ex)
        {
            JOptionPane.showMessageDialog(null, "Error: " + ex.getMessage());
        }
    }//GEN-LAST:event_btnSaveActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        this.dispose();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void btnNewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNewActionPerformed
        clearFields();
    }//GEN-LAST:event_btnNewActionPerformed

    
    //resize image
    private ImageIcon resizeImg(ImageIcon iconIn, int width, int height)
    {
        Image img = iconIn.getImage().getScaledInstance(width, height, Image.SCALE_SMOOTH);
        ImageIcon iconOut = new ImageIcon(img);
        return iconOut;
    }
    
    //method check input
    private String checkInput()
    {
        String result = "";
        if("".equals(txtProName.getText().trim()))
            result += "Vui lòng nhập tên sản phẩm\n";
        if("".equals(txtProPrice.getText().trim()))
            result += "Vui lòng nhập giá bán";
        return result;
    }
    
    //method load data to combobox
    private void loadDatatoCombobox()
    {
        DefaultComboBoxModel model1 = bllManu.getDcbModelManu();
        cbManu.setModel(model1);
    }
    
    //clear all field
    private void clearFields()
    {
        txtProName.setText("");
        txtProPrice.setText("");
        txtProPromotion.setText("");
        txtProDescription.setText("");
        txtProWarranty.setText("");
        lbID.setText("");
        lbImage.setIcon(null);
    }
    /**
     * @param args the command line arguments
     */
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnChooseImg;
    private javax.swing.JButton btnNew;
    private javax.swing.JButton btnSave;
    private javax.swing.JComboBox cbManu;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JLabel lbID;
    private javax.swing.JLabel lbImage;
    private javax.swing.JLabel lbTitle;
    private javax.swing.JTextArea txtProDescription;
    private javax.swing.JTextField txtProName;
    private javax.swing.JTextField txtProPrice;
    private javax.swing.JTextArea txtProPromotion;
    private javax.swing.JTextField txtProWarranty;
    // End of variables declaration//GEN-END:variables

    private void loadData(int id) {
        try{
            DTOProduct newDTOPro = bllPro.getProductbyID(id);
            if(newDTOPro != null)
            {
                lbID.setText(String.valueOf(newDTOPro.getProductID()));
                txtProName.setText(String.valueOf(newDTOPro.getProductName()));
                cbManu.setSelectedItem(newDTOPro.getManu());
                txtProPrice.setText(String.valueOf(newDTOPro.getProductPrice()));
                ImageIcon icon = new ImageIcon("D:\\wamp\\www\\shopcomputer\\public\\default\\images\\products\\" + String.valueOf(newDTOPro.getProductImage()));
                if(icon != null)
                    lbImage.setIcon(resizeImg(icon, 128, 110));
                txtProWarranty.setText(String.valueOf(newDTOPro.getProductWarranty()));
                txtProPromotion.setText(String.valueOf(newDTOPro.getProductPromotion()));
                txtProDescription.setText(String.valueOf(newDTOPro.getProductDescription()));
            }
        }
        catch(Exception ex){
            JOptionPane.showMessageDialog(null, "Loi, khong the tai du lieu");
        }
    }
}
